#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: expr.sh
# Description: 
#   expr integer1 operand integer2 
# 
#	 Operand Description
#	 +	   Addition
#	 -	   Subtraction
#	 \*	   Multiplication
#	 /     Integer division (any fraction in the result is dropped)
# Edit History: 
#   2011-01-19    File created.
#========================================================================

expr 8 / 3

expr 3 \* 5

expr 19 % 7
#只會印出3+2,不會計算
expr 3+2

CNT=1
CNT=`expr $CNT + 1`
echo "CNT:$CNT"

#計算有多少個pattern match的字數
ABC=abcdef
expr $ABC : '.*'
ABC=123abc
expr $ABC : '[0-9]*'

#match ()中的字串會被顯示出來 
expr abcdef : '.\([a-f]\{4\}\).'

#使用expr的四則運算

x=5
y=9
z=13

# 「*」(乘法)或「(」「)」的前面必須要放上「\」
a=`expr $x \* $y`
b=`expr \( $y + $z \) / $x`

echo "$a"
echo "$b"


#兩個(中的數字先算
foo=$(( ((5 + 3*2) - 4) / 2 ))
echo "foo:$foo"
